package com.cryrabbit.bmbhome.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cryrabbit.bmbhome.R;
import com.cryrabbit.bmbhome.utils.icon;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by CryRabbit on 2016/7/10.
 */
public class MyAdapter extends BaseAdapter {
    List<icon> icons=new ArrayList<>();
    Context context;
    int flag;
    @Override
    public int getCount() {
        return icons.size();

    }
    public MyAdapter(){

    }
    public MyAdapter(List<icon> icons,Context context,int flag){
        this.icons=icons;
        this.context=context;
        this.flag=flag;
    }
    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView img;
        TextView textView;
        if(flag==0){
            convertView= LayoutInflater.from(context).inflate(R.layout.grid,parent,false);
            img=(ImageView)convertView.findViewById(R.id.grid_img);
            textView=(TextView)convertView.findViewById(R.id.grid_text);
        }else{
            convertView=LayoutInflater.from(context).inflate(R.layout.grid_two,parent,false);
            img=(ImageView)convertView.findViewById(R.id.grid2_img);
            textView=(TextView)convertView.findViewById(R.id.grid2_text);
        }
        img.setBackgroundResource(icons.get(position).id);
        textView.setText(icons.get(position).name);
        return convertView;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }


}
